//底层由数组(ArrayList)实现的栈
public class ArrayStack<E> {
    private ArrayList<E> list;

    public ArrayStack() {
        list = new ArrayList<>();
    }

    //进栈
    public void push(E element) {
        list.add(element);
    }

    //出栈
    public E pop() {
        return list.remove(list.size() - 1);
    }

    //查看栈顶元素
    public E peek() {
        return list.get(list.size() - 1);
    }

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        return list.toString();
    }
}